<?php
/**
 * User: 昊天||597767865@qq.com
 * Date: 2019/8/30
 * Time: 9:03
 */
namespace backend\controllers;
use backend\models\LoginLog;
use Yii;

class LoginLogController extends BaseController
{
    public function actionIndex()
    {
        if(Yii::$app->request->isPost){
            $page = intval(input('page'));
            $limit = intval(input('limit'));
            $model = LoginLog::find()->joinWith('user');
            $data = $model
                ->offset(($page-1)*$limit)
                ->limit($limit)
                ->orderBy('id desc')
                ->asArray()->all();
            $count = $model->count();
            $this->api(0,'success',$count,$data);
        }
        $pageSize = $this->pageSize;
        return $this->render('index',compact('pageSize'));
    }

    /**
     * 日志删除
     * @throws \Throwable
     * @throws \yii\db\StaleObjectException
     */
    public function actionDel()
    {
        if (Yii::$app->request->isAjax){
            $id = (int)input('id');
            $model = LoginLog::findOne($id);
            if($model->delete()){
                $this->json(200,'删除成功');
            }
            $this->json(100,'删除失败');
        }
    }
}
